﻿using Microsoft.AspNetCore.Http;
using Models.Common;
using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using UtilsORM;
using UtilsORM.MySqlData;

////using System.Web.Script.Serialization;

namespace GatewayServerService.Data
{
    public class DBIotDeviceTaskTimeFixed
    {



        public iot_device_task_time_fixed getModel(string guid)
        {
            EFYihongIotContext ef = new EFYihongIotContext();
            return ef.iot_device_task_time_fixed.Where(c => c.tf_guid == guid).FirstOrDefault();
        }




        public bool saveAll(IFormCollection FC, HttpReqModel httpRequest, MagerLoginInfo LoginUserInfo, iot_device_task_time_fixed req)
        {
            EFYihongIotContext ef = new EFYihongIotContext();

            //先查一下有没重复提交
            iot_device_task_time_fixed model = ef.iot_device_task_time_fixed.Where(c => c.tf_guid == req.tf_guid).FirstOrDefault();
            if (model == null)
            {

                //写入
                req.tf_add_time = DateTime.Now;
                req.tf_mod_time = DateTime.Now;
                req.tf_start_time = DateTime.Now;
                req.tf_time_name = "时间";
                //req.tf_complete = 0;
                // req.tf_execute_count = 0;
                req.tf_c_guid = LoginUserInfo.userCompanyGuid;
                ef.iot_device_task_time_fixed.Add(req);
                ef.SaveChanges();
            }
            else
            {
                model.tf_title = req.tf_title;
                model.tf_status = req.tf_status;
                model.tf_time_value = req.tf_time_value;
                model.tf_key = req.tf_key;
                model.tf_task_guid = req.tf_task_guid;
                //model.tf_repeat_count = req.tf_repeat_count;
                model.tf_mod_time = DateTime.Now;
                ef.iot_device_task_time_fixed.Update(model);
                ef.SaveChanges();
            }
            return true;
        }
    }
}
